<?
$info = $GLOBALS['info'];
$min_year = getMinYear($GLOBALS['id']);
if(!is_numeric($min_year)){
	$min_year = date('Y');
}
$num_years = date('Y') - $min_year + 1;

if($info){
//	if(me()){
//		echo '<pre>';
//		print_r($info);
//		echo '</pre>';
//	}
	$result = getReports($info);
	//print_r($result);
	//echo '</pre>';
}
?>
<form name="reportsForm" id="reportsForm" onSubmit="return false;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td align="left"><p><strong>It's All About Numbers - Group, Sort, Explore, Manage</strong><br>
		  More financial information won't hurt anybody. Just the opposite. Use it to increase your sales and revenues.<br>
		  Analyze your clients' background and surroundings (Personal or Business), the type of currency they prefer to pay with and their modes of payment. All these can be tied to the region or the country they come from, if you select a time period of your choice. </p>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td valign="top">
				<table id="selection_tables" width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td bgcolor="#DCDCDC" colspan="4" align="center"><strong>Currency</strong></td>
				  </tr>
				  <tr>
					<td width="15"><input type="checkbox" name="info[payment_currency][0]" value="USD" <? if(!$info or (is_array($info) and in_array('USD', $info['payment_currency']))){ echo 'checked'; } ?>></td>
					<td>USD</td>
					<td width="15"><input type="checkbox" name="info[payment_currency][3]" value="CAD" <? if(!$info or (is_array($info) and in_array('CAD', $info['payment_currency']))){ echo 'checked'; } ?>></td>
					<td>CAD</td>
				  </tr>
				  <tr>
					<td><input type="checkbox" name="info[payment_currency][1]" value="GBP" <? if(!$info or (is_array($info) and in_array('GBP', $info['payment_currency']))){ echo 'checked'; } ?>></td>
					<td>GBP</td>
					<td><input type="checkbox" name="info[payment_currency][4]" value="AUD" <? if(!$info or (is_array($info) and in_array('AUD', $info['payment_currency']))){ echo 'checked'; } ?>></td>
					<td>AUD</td>
				  </tr>
				  <tr>
					<td><input type="checkbox" name="info[payment_currency][2]" value="EUR" <? if(!$info or (is_array($info) and in_array('EUR', $info['payment_currency']))){ echo 'checked'; } ?>></td>
					<td>EUR</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				  </tr>
				</table>
			</td>
			<td valign="top">
				<table id="selection_tables" width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
					  <td bgcolor="#DCDCDC" colspan="4" align="center"><strong>Client Type</strong></td>
					</tr>
					<tr>
					  <td width="15"><input type="checkbox" name="info[client_individual]" value="t" <? if(!$info or (is_array($info) and $info['client_individual'] == 't')){ echo 'checked'; } ?>></td>
					  <td><strong>Presonal</strong></td>
					  <td width="15"><input type="checkbox" name="info[client_business]" value="t" id="business" <? if(!$info or (is_array($info) and $info['client_business'] == 't')){ echo 'checked'; } ?> onClick="document.getElementById('business1').checked=this.checked;document.getElementById('business2').checked=this.checked;"></td>
					  <td><strong>Business</strong></td>
					</tr>
					<tr>
					  <td>&nbsp;</td>
					  <td>&nbsp;</td>
					  <td><input type="checkbox" name="info[client_business_novat]" value="t" id="business1" <? if(!$info or (is_array($info) and $info['client_business_novat'] == 't')){ echo 'checked'; } ?> onClick="document.getElementById('business').checked=(document.getElementById('business1').checked || document.getElementById('business2').checked);"></td>
					  <td>No VAT<sup>1</sup></td>
					</tr>
					<tr>
					  <td>&nbsp;</td>
					  <td>&nbsp;</td>
					  <td><input type="checkbox" name="info[client_business_vat]" value="t" id="business2" <? if(!$info or (is_array($info) and $info['client_business_vat'] == 't')){ echo 'checked'; } ?> onClick="document.getElementById('business').checked=(document.getElementById('business1').checked || document.getElementById('business2').checked);"></td>
					  <td>VAT<sup>2</sup></td>
					</tr>
			  </table>
			</td>
			<td valign="top">
				<table id="selection_tables" width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
					  <td bgcolor="#DCDCDC" colspan="2" align="center"><strong>Store</strong></td>
					</tr>
					<?
					foreach(getStores($GLOBALS['id']) as $k => $v){
						$checked = (!$info or (is_array($info['store_id']) and in_array($v[store_id], $info['store_id']))) ? 'checked' : '';
						echo "<tr>
							<td width='15'><input type='checkbox' name='info[store_id][$k]' value='$v[store_id]' $checked></td>
							<td>$v[title]</td>
						</tr>";
					}
					?>
				  </table>
			  </td>
		  </tr>
		</table>
	  </td>
	</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td>
			<table id="selection_tables" width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td bgcolor="#DCDCDC" colspan="10" align="center"><strong></strong><strong>Payment Gateway</strong></td>
				</tr>
				<tr>
					<td width="15"><input type="checkbox" id="worldpay" <? if(!$info or (is_array($info) and (in_array('worldpay_access', $info['payment_method']) or in_array('worldpay_recurring', $info['payment_method']) or in_array('worldpay', $info['payment_method'])))){ echo 'checked'; } ?> onClick="document.getElementById('worldpay1').checked=this.checked;document.getElementById('worldpay2').checked=this.checked;document.getElementById('worldpay3').checked=this.checked;"></td>
					<td><strong>WorldPay</strong></td>
					<td width="15"><input type="checkbox" id="paypal" <? if(!$info or (is_array($info) and (in_array('paypal_recurring', $info['payment_method']) or in_array('paypal', $info['payment_method'])))){ echo 'checked'; } ?> onClick="document.getElementById('paypal1').checked=this.checked;document.getElementById('paypal2').checked=this.checked;"></td>
					<td><strong>PayPal</strong></td>
					<td width="15"><input type="checkbox" id="2co" <? if(!$info or (is_array($info) and (in_array('2co_recurring', $info['payment_method']) or in_array('2co', $info['payment_method'])))){ echo 'checked'; } ?> onClick="document.getElementById('2co1').checked=this.checked;document.getElementById('2co2').checked=this.checked;"></td>
					<td><strong>2CheckOut</strong></td>
					<td width="15"><input type="checkbox" name="info[payment_method][3]" value="wallet" <? if(!$info or (is_array($info) and in_array('wallet', $info['payment_method']))){ echo 'checked'; } ?>></td>
					<td><strong>My Wallet</strong></td>
					<td width="15"><input type="checkbox" name="info[payment_method][10]" value="other" <? if(!$info or (is_array($info) and in_array('other', $info['payment_method']))){ echo 'checked'; } ?>></td>
					<td><strong>Other</strong></td>
				</tr>
				<tr>
					<td><input type="checkbox" name="info[payment_method][0]" value="worldpay" id="worldpay1" <? if(!$info or (is_array($info) and in_array('worldpay', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('worldpay').checked=(document.getElementById('worldpay1').checked || document.getElementById('worldpay2').checked || document.getElementById('worldpay3').checked);"></td>
					<td>Normal</td>
					<td><input type="checkbox" name="info[payment_method][1]" value="paypal" id="paypal1" <? if(!$info or (is_array($info) and in_array('paypal', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('paypal').checked=(document.getElementById('paypal1').checked || document.getElementById('paypal2').checked);"></td>
					<td>Normal</td>
					<td><input type="checkbox" name="info[payment_method][2]" value="2co" id="2co1" <? if(!$info or (is_array($info) and in_array('2co', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('2co').checked=(document.getElementById('2co1').checked || document.getElementById('2co2').checked);"></td>
					<td>Normal</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="info[payment_method][5]" value="worldpay_recurring" id="worldpay2" <? if(!$info or (is_array($info) and in_array('worldpay_recurring', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('worldpay').checked=(document.getElementById('worldpay1').checked || document.getElementById('worldpay2').checked || document.getElementById('worldpay3').checked);"></td>
					<td>Recurring</td>
					<td><input type="checkbox" name="info[payment_method][6]" value="paypal_recurring" id="paypal2" <? if(!$info or (is_array($info) and in_array('paypal_recurring', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('paypal').checked=(document.getElementById('paypal1').checked || document.getElementById('paypal2').checked);"></td>
					<td>Recurring</td>
					<td><input type="checkbox" name="info[payment_method][7]" value="2co_recurring" id="2co2" <? if(!$info or (is_array($info) and in_array('2co_recurring', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('2co').checked=(document.getElementById('2co1').checked || document.getElementById('2co2').checked);"></td>
					<td>Recurring</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="info[payment_method][9]" value="worldpay_access" id="worldpay3" <? if(!$info or (is_array($info) and in_array('worldpay_access', $info['payment_method']))){ echo 'checked'; } ?> onClick="document.getElementById('worldpay').checked=(document.getElementById('worldpay1').checked || document.getElementById('worldpay2').checked || document.getElementById('worldpay3').checked);"></td>
					<td>Access</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?
if(!$info or $info['client_country'] == 'nolocationselected'){
	$country_div1 = 'block';
	$country_div2 = 'none';
	$country_div3 = 'none';
	$selected_div1 = 'selected';
	$selected_div2 = '';
	$selected_div3 = '';
}elseif($info['client_country'] == 'noneuclient'){
	$country_div1 = 'none';
	$country_div2 = 'block';
	$country_div3 = 'none';
	$selected_div1 = '';
	$selected_div2 = 'selected';
	$selected_div3 = '';
}elseif($info['client_country'] == 'euclient'){
	$country_div1 = 'none';
	$country_div2 = 'none';
	$country_div3 = 'block';
	$selected_div1 = '';
	$selected_div2 = '';
	$selected_div3 = 'selected';
}

if(!$info or $info['period_type'] == 'noperiodselected'){
	$period_div1 = 'block';
	$period_div2 = 'none';
	$period_div3 = 'none';
	$selected_div4 = 'selected';
	$selected_div5 = '';
	$selected_div6 = '';
}elseif($info['period_type'] == 'monthyear'){
	$period_div1 = 'none';
	$period_div2 = 'block';
	$period_div3 = 'none';
	$selected_div4 = '';
	$selected_div5 = 'selected';
	$selected_div6 = '';
}elseif($info['period_type'] == 'customperiod'){
	$period_div1 = 'none';
	$period_div2 = 'none';
	$period_div3 = 'block';
	$selected_div4 = '';
	$selected_div5 = '';
	$selected_div6 = 'selected';

}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td style="background:url(images/dots_grey_line_01.gif) repeat-x center;">&nbsp;</td>
	</tr>
	</table>
	<table class="reg_table" width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	  <td>Clients Location:<br />
		<select name="info[client_country]" style="width:170px;" onChange="show_clientlocation(this.options[this.selectedIndex].value);">
		  <option value="nolocationselected" <?=$selected_div1;?>>--All Countries--</option>
		  <option value="noneuclient" <?=$selected_div2;?>>Non-EU Clients</option>
		  <option value="euclient" <?=$selected_div3;?>>EU Clients</option>
		</select></td>
	  <td>
	  	<div style="display:<?=$country_div1;?>; height:auto; color:#FF0000;" id="nolocationselected_clientlocationSpan">&larr;&nbsp;&nbsp;Please, select your location!</div>
		<div style="display:<?=$country_div2;?>; height:auto;" id="noneuclient_clientlocationSpan">Select Country:<br />
		  <select class='txt' name='info[noneuclient]'>
			<?
			if(trim($info['noneuclient'])){
				$noneucountryselected = $info['noneuclient'];
			}else{
				$noneucountryselected = '  ';
			}
			echo get_countries($noneucountryselected, false, true);
			?>
		  </select>
		</div>
		<div style="display:<?=$country_div3;?>; height:auto;" id="euclient_clientlocationSpan">Select Country:<br />
		  <select class='txt' name='info[euclient]'>
			<option></option>
			<?=get_countries($info['euclient'], true, true);?>
		  </select>
		</div></td>
	  <td>&nbsp;</td>
	</tr>
	<tr>
	  <td>Select Period:<br />
		<select style="width:170px;" name="info[period_type]" onChange="show_period(this.options[this.selectedIndex].value);">
		  <option value="noperiodselected" <?=$selected_div4;?>>--Select Period--</option>
		  <option value="monthyear" <?=$selected_div5;?>>Month / Year</option>
		  <option value="customperiod" <?=$selected_div6;?>>Custom Period</option>
		</select></td>
	  <td><div style="display:<?=$period_div1;?>; height:auto; color:#FF0000;" id="noperiodselected_periodSpan">&larr;&nbsp;&nbsp;Please, select period!</div>
		<div style="display:<?=$period_div2;?>; height:auto;" id="monthyear_periodSpan">
		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td>Select Period:<br />
				<select style="width:115px;" name="info[month]">
				  <option value="">All Months</option>
				  <?
				  for($i = 1; $i <= 12; $i++){
				  	$m1 = date('m', mktime(0, 0, 0, $i, 1, 1));
				  	$m2 = date('F', mktime(0, 0, 0, $i, 1, 1));
				  	if($m1 == $info['month']){
				  		$selected = 'selected';
				  	}else{
				  		$selected = '';
				  	}
				  	echo "<option value='$m1' $selected>$m2</option>";
				  }
				  ?>
				</select></td>
			  <td>Year:<br />
				<select style="width:60px;" name="info[year]">
				  <option value="">Any</option>
					<?
					for($i = 0; $i < $num_years; $i++){
						$year = date("Y", mktime(0, 0, 0, date('m'), 1, date('Y') - $i));
						if($info['year'] == $year){
							$selected = 'selected';
						}else{
							$selected = '';
						}
						echo "<option value='$year' $selected>$year</option>";
					}
					?>
				</select></td>
			</tr>
		  </table>
		</div>
		<div style="display:<?=$period_div3;?>; height:auto;" id="customperiod_periodSpan">
		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td valign='bottom'><a href="#" onClick="popUpCalendar(reportsForm, reportsForm.sdate, reportsForm.sdate, 'yyyy-mm-dd');return false;"><img src="images/calendar.gif" alt="Select Date" border="0" align="absmiddle"></a></td>
				<td>Start Date:<br />
				<input name="info[sdate]" type="text" size="10" id="sdate" maxlength="10" value="<?=$info[sdate];?>" /></td>
				<td valign='bottom'><a href="#" onClick="popUpCalendar(reportsForm, reportsForm.edate, reportsForm.edate, 'yyyy-mm-dd');return false;"><img src="images/calendar.gif" alt="Select Date" border="0" align="absmiddle"></a></td>
				<td>End Date:<br />
				<input name="info[edate]" type="text" size="10" id="edate" maxlength="10" value="<?=$info[edate];?>" /></td>
			</tr>
		  </table>
		</div></td>
	  <td><br />
		<input name="" type="submit" value="&nbsp;&nbsp;View Report&nbsp;&nbsp;" onClick="openPage('reports.html', getFormData('reportsForm'));"></td>
	</tr>
</table>
</form>
<br />
<br />
<?
if($result['paypal'] or $result['paypal_recurring']){
	$paypal_total_usd_individual = 0;
	$paypal_total_usd_business = 0;
	$paypal_wholesale_usd_individual = 0;
	$paypal_wholesale_usd_business = 0;

	// Start PayPal Table
	$paypal_table = "
	<table class='RevTable' width='100%' border='0' cellspacing='1' cellpadding='0'>
	  <tr>
	    <td id='Main_TReport' align='center'><img align='absmiddle' src='images/ico_main_treport.gif' alt='Revenue Report'>&nbsp;<img src='images/paypal_logo_rev_b.gif' alt='PayPal' align='absmiddle'>&nbsp;<b>REVENUE REPORT</b></td>
	  </tr>";

	if($result['paypal']['individual']){
		$paypal_table .= "<tr>
			<td>
				<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
				  <tr>
					<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; SINGLE TRANSACTIONS</b></td>
					</tr>
				  <tr>
					<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
					<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
					<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
					</tr>
				  <tr>
					<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
					<td id='irt_GS1' align='center'><b>Retail</b></td>
					<td id='irt_GS2' align='center'><b>Wholesale</b></td>
					<td id='irt_GS1' align='center'><b>Retail</b></td>
					<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				  </tr>";
		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['paypal']['individual'][$k]){
				$t_inv_usd = $result['paypal']['individual'][$k]['inv']['total_usd'] ? $result['paypal']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['paypal']['individual'][$k]['cn']['total_usd'] ? $result['paypal']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['paypal']['individual'][$k]['inv']['wholesale_usd'] ? $result['paypal']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['paypal']['individual'][$k]['cn']['wholesale_usd'] ? $result['paypal']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$paypal_total_usd_individual = $paypal_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$paypal_wholesale_usd_individual = $paypal_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['paypal']['individual'][$k]['inv']['total'] ? $result['paypal']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['paypal']['individual'][$k]['inv']['wholesale'] ? $result['paypal']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['paypal']['individual'][$k]['cn']['total'] ? $result['paypal']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['paypal']['individual'][$k]['cn']['wholesale'] ? $result['paypal']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$paypal_table .=  "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$paypal_table .= '</table></td></tr>';
	}

	if($result['paypal']['business_novat']){
		$paypal_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
			  </tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";
		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['paypal']['business_novat'][$k]){
				$t_inv_usd = $result['paypal']['business_novat'][$k]['inv']['total_usd'] ? $result['paypal']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['paypal']['business_novat'][$k]['cn']['total_usd'] ? $result['paypal']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['paypal']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['paypal']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['paypal']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['paypal']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$paypal_total_usd_business = $paypal_total_usd_business + $t_inv_usd + $t_cn_usd;
				$paypal_wholesale_usd_business = $paypal_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['paypal']['business_novat'][$k]['inv']['total'] ? $result['paypal']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['paypal']['business_novat'][$k]['inv']['wholesale'] ? $result['paypal']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['paypal']['business_novat'][$k]['cn']['total'] ? $result['paypal']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['paypal']['business_novat'][$k]['cn']['wholesale'] ? $result['paypal']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$paypal_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$paypal_table .= '</table></td></tr>';
	}

	if($result['paypal']['business_vat']){
		$paypal_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
			  </tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

			foreach($GLOBALS['currencies'] as $k => $v){
				if($result['paypal']['business_vat'][$k]){
					$t_inv_usd = $result['paypal']['business_vat'][$k]['inv']['total_usd'] ? $result['paypal']['business_vat'][$k]['inv']['total_usd'] : 0;
					$t_cn_usd = $result['paypal']['business_vat'][$k]['cn']['total_usd'] ? $result['paypal']['business_vat'][$k]['cn']['total_usd'] : 0;
					$wh_inv_usd = $result['paypal']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['paypal']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
					$wh_cn_usd = $result['paypal']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['paypal']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

					$paypal_total_usd_business = $paypal_total_usd_business + $t_inv_usd + $t_cn_usd;
					$paypal_wholesale_usd_business = $paypal_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

					$total_inv = $result['paypal']['business_vat'][$k]['inv']['total'] ? $result['paypal']['business_vat'][$k]['inv']['total'] : 0;
					$wholesale_inv = $result['paypal']['business_vat'][$k]['inv']['wholesale'] ? $result['paypal']['business_vat'][$k]['inv']['wholesale'] : 0;
					$total_cn = $result['paypal']['business_vat'][$k]['cn']['total'] ? $result['paypal']['business_vat'][$k]['cn']['total'] : 0;
					$wholesale_cn = $result['paypal']['business_vat'][$k]['cn']['wholesale'] ? $result['paypal']['business_vat'][$k]['cn']['wholesale'] : 0;
					$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
					$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
					$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
					$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
					$paypal_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
						<td align='center'>$k</td>
						<td id='irt_pr20'>$total_inv</td>
						<td id='irt_pr20'>$wholesale_inv</td>
						<td id='irt_pr20'><font color='red'>$total_cn</font></td>
						<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
					</tr>";
				}
			}

		$paypal_table .= '</table></td></tr>';
	}

	if($result['paypal_recurring']['individual']){
		$paypal_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
				<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['paypal_recurring']['individual'][$k]){
				$t_inv_usd = $result['paypal_recurring']['individual'][$k]['inv']['total_usd'] ? $result['paypal_recurring']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['paypal_recurring']['individual'][$k]['cn']['total_usd'] ? $result['paypal_recurring']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['paypal_recurring']['individual'][$k]['inv']['wholesale_usd'] ? $result['paypal_recurring']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['paypal_recurring']['individual'][$k]['cn']['wholesale_usd'] ? $result['paypal_recurring']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$paypal_total_usd_individual = $paypal_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$paypal_wholesale_usd_individual = $paypal_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['paypal_recurring']['individual'][$k]['inv']['total'] ? $result['paypal_recurring']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['paypal_recurring']['individual'][$k]['inv']['wholesale'] ? $result['paypal_recurring']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['paypal_recurring']['individual'][$k]['cn']['total'] ? $result['paypal_recurring']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['paypal_recurring']['individual'][$k]['cn']['wholesale'] ? $result['paypal_recurring']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$paypal_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$paypal_table .= '</table></td></tr>';
	}

	if($result['paypal_recurring']['business_novat']){
		$paypal_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; RECURRING TRANSACTIONS</b></td>
			  </tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['paypal_recurring']['business_novat'][$k]){
				$t_inv_usd = $result['paypal_recurring']['business_novat'][$k]['inv']['total_usd'] ? $result['paypal_recurring']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['paypal_recurring']['business_novat'][$k]['cn']['total_usd'] ? $result['paypal_recurring']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['paypal_recurring']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['paypal_recurring']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['paypal_recurring']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['paypal_recurring']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$paypal_total_usd_business = $paypal_total_usd_business + $t_inv_usd + $t_cn_usd;
				$paypal_wholesale_usd_business = $paypal_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['paypal_recurring']['business_novat'][$k]['inv']['total'] ? $result['paypal_recurring']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['paypal_recurring']['business_novat'][$k]['inv']['wholesale'] ? $result['paypal_recurring']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['paypal_recurring']['business_novat'][$k]['cn']['total'] ? $result['paypal_recurring']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['paypal_recurring']['business_novat'][$k]['cn']['wholesale'] ? $result['paypal_recurring']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$paypal_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$paypal_table .= '</table></td></tr>';
	}

	if($result['paypal_recurring']['business_vat']){
		$paypal_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; RECURRING TRANSACTIONS</b></td>
			  </tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['paypal_recurring']['business_vat'][$k]){
				$t_inv_usd = $result['paypal_recurring']['business_vat'][$k]['inv']['total_usd'] ? $result['paypal_recurring']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['paypal_recurring']['business_vat'][$k]['cn']['total_usd'] ? $result['paypal_recurring']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['paypal_recurring']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['paypal_recurring']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['paypal_recurring']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['paypal_recurring']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$paypal_total_usd_business = $paypal_total_usd_business + $t_inv_usd + $t_cn_usd;
				$paypal_wholesale_usd_business = $paypal_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['paypal_recurring']['business_vat'][$k]['inv']['total'] ? $result['paypal_recurring']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['paypal_recurring']['business_vat'][$k]['inv']['wholesale'] ? $result['paypal_recurring']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['paypal_recurring']['business_vat'][$k]['cn']['total'] ? $result['paypal_recurring']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['paypal_recurring']['business_vat'][$k]['cn']['wholesale'] ? $result['paypal_recurring']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$paypal_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$paypal_table .= '</table></td></tr>';
	}

	$paypal_total_usd_sum = $paypal_total_usd_individual + $paypal_total_usd_business;
	$paypal_wholesale_usd_sum = $paypal_wholesale_usd_individual + $paypal_wholesale_usd_business;

	$paypal_share_individual = get_persentage($paypal_wholesale_usd_individual, $paypal_wholesale_usd_sum);
	$paypal_share_business = get_persentage($paypal_wholesale_usd_business, $paypal_wholesale_usd_sum);
	// End PayPal Table
}

if($result['worldpay'] or $result['worldpay_recurring'] or $result['worldpay_access']){
	$worldpay_total_usd_individual = 0;
	$worldpay_total_usd_business = 0;
	$worldpay_wholesale_usd_individual = 0;
	$worldpay_wholesale_usd_business = 0;

	// Start WorldPay Table
	$worldpay_table = "<table class='RevTable' width='100%' border='0' cellspacing='1' cellpadding='0'>
	  <tr>
	    <td id='Main_TReport' align='center'><img align='absmiddle' src='images/ico_main_treport.gif' alt='Revenue Report'>&nbsp;<img src='images/worldpay_logo_rev_b.gif' alt='WorldPay' align='absmiddle'>&nbsp;<b>REVENUE REPORT</b></td>
	  </tr>";

	if($result['worldpay']['individual']){

	$worldpay_table .= "<tr>
	<td>
		<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; SINGLE TRANSACTIONS</b></td>
			</tr>
		  <tr>
			<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
			<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
			<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
			</tr>
		  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
		  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay']['individual'][$k]){
				$t_inv_usd = $result['worldpay']['individual'][$k]['inv']['total_usd'] ? $result['worldpay']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay']['individual'][$k]['cn']['total_usd'] ? $result['worldpay']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay']['individual'][$k]['inv']['wholesale_usd'] ? $result['worldpay']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay']['individual'][$k]['cn']['wholesale_usd'] ? $result['worldpay']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_individual = $worldpay_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_individual = $worldpay_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay']['individual'][$k]['inv']['total'] ? $result['worldpay']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay']['individual'][$k]['inv']['wholesale'] ? $result['worldpay']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay']['individual'][$k]['cn']['total'] ? $result['worldpay']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay']['individual'][$k]['cn']['wholesale'] ? $result['worldpay']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay']['business_novat']){

		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay']['business_novat'][$k]){
				$t_inv_usd = $result['worldpay']['business_novat'][$k]['inv']['total_usd'] ? $result['worldpay']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay']['business_novat'][$k]['cn']['total_usd'] ? $result['worldpay']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['worldpay']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['worldpay']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_business = $worldpay_total_usd_business + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_business = $worldpay_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay']['business_novat'][$k]['inv']['total'] ? $result['worldpay']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay']['business_novat'][$k]['inv']['wholesale'] ? $result['worldpay']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay']['business_novat'][$k]['cn']['total'] ? $result['worldpay']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay']['business_novat'][$k]['cn']['wholesale'] ? $result['worldpay']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay']['business_vat']){
		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay']['business_vat'][$k]){
				$t_inv_usd = $result['worldpay']['business_vat'][$k]['inv']['total_usd'] ? $result['worldpay']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay']['business_vat'][$k]['cn']['total_usd'] ? $result['worldpay']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['worldpay']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['worldpay']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_business = $worldpay_total_usd_business + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_business = $worldpay_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay']['business_vat'][$k]['inv']['total'] ? $result['worldpay']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay']['business_vat'][$k]['inv']['wholesale'] ? $result['worldpay']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay']['business_vat'][$k]['cn']['total'] ? $result['worldpay']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay']['business_vat'][$k]['cn']['wholesale'] ? $result['worldpay']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay_recurring']['individual']){
		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
				<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay_recurring']['individual'][$k]){
				$t_inv_usd = $result['worldpay_recurring']['individual'][$k]['inv']['total_usd'] ? $result['worldpay_recurring']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay_recurring']['individual'][$k]['cn']['total_usd'] ? $result['worldpay_recurring']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay_recurring']['individual'][$k]['inv']['wholesale_usd'] ? $result['worldpay_recurring']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay_recurring']['individual'][$k]['cn']['wholesale_usd'] ? $result['worldpay_recurring']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_individual = $worldpay_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_individual = $worldpay_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay_recurring']['individual'][$k]['inv']['total'] ? $result['worldpay_recurring']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay_recurring']['individual'][$k]['inv']['wholesale'] ? $result['worldpay_recurring']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay_recurring']['individual'][$k]['cn']['total'] ? $result['worldpay_recurring']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay_recurring']['individual'][$k]['cn']['wholesale'] ? $result['worldpay_recurring']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay_recurring']['business_novat']){
		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay_recurring']['business_novat'][$k]){
				$t_inv_usd = $result['worldpay_recurring']['business_novat'][$k]['inv']['total_usd'] ? $result['worldpay_recurring']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay_recurring']['business_novat'][$k]['cn']['total_usd'] ? $result['worldpay_recurring']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay_recurring']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['worldpay_recurring']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay_recurring']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['worldpay_recurring']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_business = $worldpay_total_usd_business + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_business = $worldpay_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay_recurring']['business_novat'][$k]['inv']['total'] ? $result['worldpay_recurring']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay_recurring']['business_novat'][$k]['inv']['wholesale'] ? $result['worldpay_recurring']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay_recurring']['business_novat'][$k]['cn']['total'] ? $result['worldpay_recurring']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay_recurring']['business_novat'][$k]['cn']['wholesale'] ? $result['worldpay_recurring']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay_recurring']['business_vat']){

		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay_recurring']['business_vat'][$k]){
				$t_inv_usd = $result['worldpay_recurring']['business_vat'][$k]['inv']['total_usd'] ? $result['worldpay_recurring']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay_recurring']['business_vat'][$k]['cn']['total_usd'] ? $result['worldpay_recurring']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay_recurring']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['worldpay_recurring']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay_recurring']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['worldpay_recurring']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_business = $worldpay_total_usd_business + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_business = $worldpay_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay_recurring']['business_vat'][$k]['inv']['total'] ? $result['worldpay_recurring']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay_recurring']['business_vat'][$k]['inv']['wholesale'] ? $result['worldpay_recurring']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay_recurring']['business_vat'][$k]['cn']['total'] ? $result['worldpay_recurring']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay_recurring']['business_vat'][$k]['cn']['wholesale'] ? $result['worldpay_recurring']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay_access']['individual']){
		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
				<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; ACCESS TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay_access']['individual'][$k]){
				$t_inv_usd = $result['worldpay_access']['individual'][$k]['inv']['total_usd'] ? $result['worldpay_access']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay_access']['individual'][$k]['cn']['total_usd'] ? $result['worldpay_access']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay_access']['individual'][$k]['inv']['wholesale_usd'] ? $result['worldpay_access']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay_access']['individual'][$k]['cn']['wholesale_usd'] ? $result['worldpay_access']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_individual = $worldpay_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_individual = $worldpay_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay_access']['individual'][$k]['inv']['total'] ? $result['worldpay_access']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay_access']['individual'][$k]['inv']['wholesale'] ? $result['worldpay_access']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay_access']['individual'][$k]['cn']['total'] ? $result['worldpay_access']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay_access']['individual'][$k]['cn']['wholesale'] ? $result['worldpay_access']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .=  "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay_access']['business_novat']){
		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; ACCESS TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay_access']['business_novat'][$k]){
				$t_inv_usd = $result['worldpay_access']['business_novat'][$k]['inv']['total_usd'] ? $result['worldpay_access']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay_access']['business_novat'][$k]['cn']['total_usd'] ? $result['worldpay_access']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay_access']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['worldpay_access']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay_access']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['worldpay_access']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_business = $worldpay_total_usd_business + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_business = $worldpay_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay_access']['business_novat'][$k]['inv']['total'] ? $result['worldpay_access']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay_access']['business_novat'][$k]['inv']['wholesale'] ? $result['worldpay_access']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay_access']['business_novat'][$k]['cn']['total'] ? $result['worldpay_access']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay_access']['business_novat'][$k]['cn']['wholesale'] ? $result['worldpay_access']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$worldpay_table .= '</table></td></tr>';
	}

	if($result['worldpay_access']['business_vat']){
		$worldpay_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; ACCESS TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['worldpay_access']['business_vat'][$k]){
				$t_inv_usd = $result['worldpay_access']['business_vat'][$k]['inv']['total_usd'] ? $result['worldpay_access']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['worldpay_access']['business_vat'][$k]['cn']['total_usd'] ? $result['worldpay_access']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['worldpay_access']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['worldpay_access']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['worldpay_access']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['worldpay_access']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$worldpay_total_usd_business = $worldpay_total_usd_business + $t_inv_usd + $t_cn_usd;
				$worldpay_wholesale_usd_business = $worldpay_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['worldpay_access']['business_vat'][$k]['inv']['total'] ? $result['worldpay_access']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['worldpay_access']['business_vat'][$k]['inv']['wholesale'] ? $result['worldpay_access']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['worldpay_access']['business_vat'][$k]['cn']['total'] ? $result['worldpay_access']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['worldpay_access']['business_vat'][$k]['cn']['wholesale'] ? $result['worldpay_access']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$worldpay_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$worldpay_table .= '</table></td></tr>';
	}

	$worldpay_total_usd_sum = $worldpay_total_usd_individual + $worldpay_total_usd_business;
	$worldpay_wholesale_usd_sum = $worldpay_wholesale_usd_individual + $worldpay_wholesale_usd_business;

	$worldpay_share_individual = get_persentage($worldpay_wholesale_usd_individual, $worldpay_wholesale_usd_sum);
	$worldpay_share_business = get_persentage($worldpay_wholesale_usd_business, $worldpay_wholesale_usd_sum);
	// End WorldPay Table
}

if($result['2co'] or $result['2co_recurring']){
	$co_total_usd_individual = 0;
	$co_wholesale_usd_individual = 0;
	$co_total_usd_business = 0;
	$co_wholesale_usd_business = 0;

	// Start 2CheckOut Table
	$co_table = "<table class='RevTable' width='100%' border='0' cellspacing='1' cellpadding='0'>
	  <tr>
	    <td id='Main_TReport' align='center'><img align='absmiddle' src='images/ico_main_treport.gif' alt='Revenue Report'>&nbsp;<img src='images/2co_logo_rev_b.gif' alt='2CHECKOUT' align='absmiddle'>&nbsp;<b>REVENUE REPORT</b></td>
	  </tr>";

	if($result['2co']['individual']){

		$co_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
				<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['2co']['individual'][$k]){
				$t_inv_usd = $result['2co']['individual'][$k]['inv']['total_usd'] ? $result['2co']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['2co']['individual'][$k]['cn']['total_usd'] ? $result['2co']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['2co']['individual'][$k]['inv']['wholesale_usd'] ? $result['2co']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['2co']['individual'][$k]['cn']['wholesale_usd'] ? $result['2co']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$co_total_usd_individual = $co_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$co_wholesale_usd_individual = $co_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['2co']['individual'][$k]['inv']['total'] ? $result['2co']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['2co']['individual'][$k]['inv']['wholesale'] ? $result['2co']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['2co']['individual'][$k]['cn']['total'] ? $result['2co']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['2co']['individual'][$k]['cn']['wholesale'] ? $result['2co']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$co_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$co_table .= '</table></td></tr>';
	}

	if($result['2co']['business_novat']){
		$co_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['2co']['business_novat'][$k]){
				$t_inv_usd = $result['2co']['business_novat'][$k]['inv']['total_usd'] ? $result['2co']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['2co']['business_novat'][$k]['cn']['total_usd'] ? $result['2co']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['2co']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['2co']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['2co']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['2co']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$co_total_usd_business = $co_total_usd_business + $t_inv_usd + $t_cn_usd;
				$co_wholesale_usd_business = $co_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['2co']['business_novat'][$k]['inv']['total'] ? $result['2co']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['2co']['business_novat'][$k]['inv']['wholesale'] ? $result['2co']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['2co']['business_novat'][$k]['cn']['total'] ? $result['2co']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['2co']['business_novat'][$k]['cn']['wholesale'] ? $result['2co']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$co_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$co_table .= '</table></td></tr>';
	}

	if($result['2co']['business_vat']){
		$co_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['2co']['business_vat'][$k]){
				$t_inv_usd = $result['2co']['business_vat'][$k]['inv']['total_usd'] ? $result['2co']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['2co']['business_vat'][$k]['cn']['total_usd'] ? $result['2co']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['2co']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['2co']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['2co']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['2co']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$co_total_usd_business = $co_total_usd_business + $t_inv_usd + $t_cn_usd;
				$co_wholesale_usd_business = $co_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['2co']['business_vat'][$k]['inv']['total'] ? $result['2co']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['2co']['business_vat'][$k]['inv']['wholesale'] ? $result['2co']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['2co']['business_vat'][$k]['cn']['total'] ? $result['2co']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['2co']['business_vat'][$k]['cn']['wholesale'] ? $result['2co']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$co_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$co_table .= '</table></td></tr>';
	}

	if($result['2co_recurring']['individual']){
		$co_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
				<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['2co_recurring']['individual'][$k]){
				$t_inv_usd = $result['2co_recurring']['individual'][$k]['inv']['total_usd'] ? $result['2co_recurring']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['2co_recurring']['individual'][$k]['cn']['total_usd'] ? $result['2co_recurring']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['2co_recurring']['individual'][$k]['inv']['wholesale_usd'] ? $result['2co_recurring']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['2co_recurring']['individual'][$k]['cn']['wholesale_usd'] ? $result['2co_recurring']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$co_total_usd_individual = $co_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$co_wholesale_usd_individual = $co_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['2co_recurring']['individual'][$k]['inv']['total'] ? $result['2co_recurring']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['2co_recurring']['individual'][$k]['inv']['wholesale'] ? $result['2co_recurring']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['2co_recurring']['individual'][$k]['cn']['total'] ? $result['2co_recurring']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['2co_recurring']['individual'][$k]['cn']['wholesale'] ? $result['2co_recurring']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$co_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$co_table .= '</table></td></tr>';
	}

	if($result['2co_recurring']['business_novat']){
		$co_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['2co_recurring']['business_novat'][$k]){
				$t_inv_usd = $result['2co_recurring']['business_novat'][$k]['inv']['total_usd'] ? $result['2co_recurring']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['2co_recurring']['business_novat'][$k]['cn']['total_usd'] ? $result['2co_recurring']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['2co_recurring']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['2co_recurring']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['2co_recurring']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['2co_recurring']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$co_total_usd_business = $co_total_usd_business + $t_inv_usd + $t_cn_usd;
				$co_wholesale_usd_business = $co_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['2co_recurring']['business_novat'][$k]['inv']['total'] ? $result['2co_recurring']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['2co_recurring']['business_novat'][$k]['inv']['wholesale'] ? $result['2co_recurring']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['2co_recurring']['business_novat'][$k]['cn']['total'] ? $result['2co_recurring']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['2co_recurring']['business_novat'][$k]['cn']['wholesale'] ? $result['2co_recurring']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$co_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$co_table .= '</table></td></tr>';
	}

	if($result['2co_recurring']['business_vat']){
		$co_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; RECURRING TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['2co_recurring']['business_vat'][$k]){
				$t_inv_usd = $result['2co_recurring']['business_vat'][$k]['inv']['total_usd'] ? $result['2co_recurring']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['2co_recurring']['business_vat'][$k]['cn']['total_usd'] ? $result['2co_recurring']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['2co_recurring']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['2co_recurring']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['2co_recurring']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['2co_recurring']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$co_total_usd_business = $co_total_usd_business + $t_inv_usd + $t_cn_usd;
				$co_wholesale_usd_business = $co_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['2co_recurring']['business_vat'][$k]['inv']['total'] ? $result['2co_recurring']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['2co_recurring']['business_vat'][$k]['inv']['wholesale'] ? $result['2co_recurring']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['2co_recurring']['business_vat'][$k]['cn']['total'] ? $result['2co_recurring']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['2co_recurring']['business_vat'][$k]['cn']['wholesale'] ? $result['2co_recurring']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$co_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$co_table .= '</table></td></tr>';
	}

	$co_total_usd_sum = $co_total_usd_individual + $co_total_usd_business;
	$co_wholesale_usd_sum = $co_wholesale_usd_individual + $co_wholesale_usd_business;

	$co_share_individual = get_persentage($co_wholesale_usd_individual, $co_wholesale_usd_sum);
	$co_share_business = get_persentage($co_wholesale_usd_business, $co_wholesale_usd_sum);
	// End 2CheckOut Table
}

if($result['wallet']){
	$wallet_total_usd_individual = 0;
	$wallet_wholesale_usd_individual = 0;
	$wallet_total_usd_business = 0;
	$wallet_wholesale_usd_business = 0;

	// Start Wallet Table

	$wallet_table = "<table class='RevTable' width='100%' border='0' cellspacing='1' cellpadding='0'>
	<tr>
	<td id='Main_TReport' align='center'><img align='absmiddle' src='images/ico_main_treport.gif' alt='Revenue Report'><b> WALLET REVENUE REPORT</b></td>
	</tr>";

	if($result['wallet']['individual']){

		$wallet_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
				<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['wallet']['individual'][$k]){
				$t_inv_usd = $result['wallet']['individual'][$k]['inv']['total_usd'] ? $result['wallet']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['wallet']['individual'][$k]['cn']['total_usd'] ? $result['wallet']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['wallet']['individual'][$k]['inv']['wholesale_usd'] ? $result['wallet']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['wallet']['individual'][$k]['cn']['wholesale_usd'] ? $result['wallet']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$wallet_total_usd_individual = $wallet_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$wallet_wholesale_usd_individual = $wallet_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['wallet']['individual'][$k]['inv']['total'] ? $result['wallet']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['wallet']['individual'][$k]['inv']['wholesale'] ? $result['wallet']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['wallet']['individual'][$k]['cn']['total'] ? $result['wallet']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['wallet']['individual'][$k]['cn']['wholesale'] ? $result['wallet']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$wallet_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$wallet_table .= '</table></td></tr>';
	}

	if($result['wallet']['business_novat']){
		$wallet_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['wallet']['business_novat'][$k]){
				$t_inv_usd = $result['wallet']['business_novat'][$k]['inv']['total_usd'] ? $result['wallet']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['wallet']['business_novat'][$k]['cn']['total_usd'] ? $result['wallet']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['wallet']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['wallet']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['wallet']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['wallet']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$wallet_total_usd_business = $wallet_total_usd_business + $t_inv_usd + $t_cn_usd;
				$wallet_wholesale_usd_business = $wallet_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['wallet']['business_novat'][$k]['inv']['total'] ? $result['wallet']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['wallet']['business_novat'][$k]['inv']['wholesale'] ? $result['wallet']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['wallet']['business_novat'][$k]['cn']['total'] ? $result['wallet']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['wallet']['business_novat'][$k]['cn']['wholesale'] ? $result['wallet']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$wallet_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}
		$wallet_table .= '</table></td></tr>';
	}

	if($result['wallet']['business_vat']){
		$wallet_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['wallet']['business_vat'][$k]){
				$t_inv_usd = $result['wallet']['business_vat'][$k]['inv']['total_usd'] ? $result['wallet']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['wallet']['business_vat'][$k]['cn']['total_usd'] ? $result['wallet']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['wallet']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['wallet']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['wallet']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['wallet']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$wallet_total_usd_business = $wallet_total_usd_business + $t_inv_usd + $t_cn_usd;
				$wallet_wholesale_usd_business = $wallet_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['wallet']['business_vat'][$k]['inv']['total'] ? $result['wallet']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['wallet']['business_vat'][$k]['inv']['wholesale'] ? $result['wallet']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['wallet']['business_vat'][$k]['cn']['total'] ? $result['wallet']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['wallet']['business_vat'][$k]['cn']['wholesale'] ? $result['wallet']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$wallet_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$wallet_table .= '</table></td></tr>';
	}

	$wallet_total_usd_sum = $wallet_total_usd_business + $wallet_total_usd_individual;
	$wallet_wholesale_usd_sum = $wallet_wholesale_usd_business + $wallet_wholesale_usd_individual;

	$wallet_share_individual = get_persentage($wallet_wholesale_usd_individual, $wallet_wholesale_usd_sum);
	$wallet_share_business = get_persentage($wallet_wholesale_usd_business, $wallet_wholesale_usd_sum);
	// End Wallet Table
}

if($result['other']){
	$other_total_usd_individual = 0;
	$other_wholesale_usd_individual = 0;
	$other_total_usd_business = 0;
	$other_wholesale_usd_business = 0;

	// Start Other Table
	$other_table = "<table class='RevTable' width='100%' border='0' cellspacing='1' cellpadding='0'>
	<tr>
	<td id='Main_TReport' align='center'><img align='absmiddle' src='images/ico_main_treport.gif' alt='Revenue Report'><b> OTHER PAYMENT METHODS REVENUE REPORT</b></td>
	</tr>";

if($result['other']['individual']){

	$other_table .= "<tr>
	<td>
		<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Individual Accounts &raquo; SINGLE TRANSACTIONS</b></td>
			</tr>
		  <tr>
			<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
			<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
			<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
			</tr>
		  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
		  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['other']['individual'][$k]){
				$t_inv_usd = $result['other']['individual'][$k]['inv']['total_usd'] ? $result['other']['individual'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['other']['individual'][$k]['cn']['total_usd'] ? $result['other']['individual'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['other']['individual'][$k]['inv']['wholesale_usd'] ? $result['other']['individual'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['other']['individual'][$k]['cn']['wholesale_usd'] ? $result['other']['individual'][$k]['cn']['wholesale_usd'] : 0;

				$other_total_usd_individual = $other_total_usd_individual + $t_inv_usd + $t_cn_usd;
				$other_wholesale_usd_individual = $other_wholesale_usd_individual + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['other']['individual'][$k]['inv']['total'] ? $result['other']['individual'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['other']['individual'][$k]['inv']['wholesale'] ? $result['other']['individual'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['other']['individual'][$k]['cn']['total'] ? $result['other']['individual'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['other']['individual'][$k]['cn']['wholesale'] ? $result['other']['individual'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$other_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$other_table .= '</table></td></tr>';
	}

	if($result['other']['business_novat']){

		$other_table .= "<tr>
		<td>
			<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business No VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
				</tr>
			  <tr>
				<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
				<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
				<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
				</tr>
			  <tr>
				<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
				<td id='irt_GS1' align='center'><b>Retail</b></td>
				<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['other']['business_novat'][$k]){
				$t_inv_usd = $result['other']['business_novat'][$k]['inv']['total_usd'] ? $result['other']['business_novat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['other']['business_novat'][$k]['cn']['total_usd'] ? $result['other']['business_novat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['other']['business_novat'][$k]['inv']['wholesale_usd'] ? $result['other']['business_novat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['other']['business_novat'][$k]['cn']['wholesale_usd'] ? $result['other']['business_novat'][$k]['cn']['wholesale_usd'] : 0;

				$other_total_usd_business = $other_total_usd_business + $t_inv_usd + $t_cn_usd;
				$other_wholesale_usd_business = $other_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['other']['business_novat'][$k]['inv']['total'] ? $result['other']['business_novat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['other']['business_novat'][$k]['inv']['wholesale'] ? $result['other']['business_novat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['other']['business_novat'][$k]['cn']['total'] ? $result['other']['business_novat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['other']['business_novat'][$k]['cn']['wholesale'] ? $result['other']['business_novat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$other_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$other_table .= '</table></td></tr>';
	}

if($result['other']['business_vat']){

	$other_table .= "<tr>
	<td>
		<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
		<td colspan='5' id='irt_head'>&nbsp;&nbsp;<img src='images/bullet_irt_head.gif'>&nbsp;<b>Business VAT</b><sup style='font-size:8px'>1</sup>  <b>Accounts &raquo; SINGLE TRANSACTIONS</b></td>
			</tr>
		  <tr>
			<td id='irt_gcurr' align='center'>&nbsp;&nbsp;<b>CURRENCY</b>&nbsp;&nbsp;</td>
			<td id='irt_Bcurr' align='center' colspan='2'><b>INVOICES</b></td>
			<td id='irt_Rcurr' align='center' colspan='2'><b>CREDIT NOTES</b></td>
			</tr>
		  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>-</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
		  </tr>";

		foreach($GLOBALS['currencies'] as $k => $v){
			if($result['other']['business_vat'][$k]){
				$t_inv_usd = $result['other']['business_vat'][$k]['inv']['total_usd'] ? $result['other']['business_vat'][$k]['inv']['total_usd'] : 0;
				$t_cn_usd = $result['other']['business_vat'][$k]['cn']['total_usd'] ? $result['other']['business_vat'][$k]['cn']['total_usd'] : 0;
				$wh_inv_usd = $result['other']['business_vat'][$k]['inv']['wholesale_usd'] ? $result['other']['business_vat'][$k]['inv']['wholesale_usd'] : 0;
				$wh_cn_usd = $result['other']['business_vat'][$k]['cn']['wholesale_usd'] ? $result['other']['business_vat'][$k]['cn']['wholesale_usd'] : 0;

				$other_total_usd_business = $other_total_usd_business + $t_inv_usd + $t_cn_usd;
				$other_wholesale_usd_business = $other_wholesale_usd_business + $wh_inv_usd + $wh_cn_usd;

				$total_inv = $result['other']['business_vat'][$k]['inv']['total'] ? $result['other']['business_vat'][$k]['inv']['total'] : 0;
				$wholesale_inv = $result['other']['business_vat'][$k]['inv']['wholesale'] ? $result['other']['business_vat'][$k]['inv']['wholesale'] : 0;
				$total_cn = $result['other']['business_vat'][$k]['cn']['total'] ? $result['other']['business_vat'][$k]['cn']['total'] : 0;
				$wholesale_cn = $result['other']['business_vat'][$k]['cn']['wholesale'] ? $result['other']['business_vat'][$k]['cn']['wholesale'] : 0;
				$total_inv = $v.' '.number_format($total_inv, 2, ',', ' ');
				$wholesale_inv = $v.' '.number_format($wholesale_inv, 2, ',', ' ');
				$total_cn = $v.' '.number_format($total_cn, 2, ',', ' ');
				$wholesale_cn = $v.' '.number_format($wholesale_cn, 2, ',', ' ');
				$other_table .= "<tr onMouseOver=\"this.style.backgroundColor='#FFFFCC';\" onMouseOut=\"this.style.backgroundColor='';\">
					<td align='center'>$k</td>
					<td id='irt_pr20'>$total_inv</td>
					<td id='irt_pr20'>$wholesale_inv</td>
					<td id='irt_pr20'><font color='red'>$total_cn</font></td>
					<td id='irt_pr20'><font color='red'>$wholesale_cn</font></td>
				</tr>";
			}
		}

		$other_table .= '</table></td></tr>';
	}

	$other_total_usd_sum = $other_total_usd_business + $other_total_usd_individual;
	$other_wholesale_usd_sum = $other_wholesale_usd_business + $other_wholesale_usd_individual;

	$other_share_individual = get_persentage($other_wholesale_usd_individual, $other_wholesale_usd_sum);
	$other_share_business = get_persentage($other_wholesale_usd_business, $other_wholesale_usd_sum);
	// End Other Table
}

$individual_total = $paypal_total_usd_individual + $worldpay_total_usd_individual + $co_total_usd_individual + $wallet_total_usd_individual + $other_total_usd_individual;
$individual_wholesale = $paypal_wholesale_usd_individual + $worldpay_wholesale_usd_individual + $co_wholesale_usd_individual + $wallet_wholesale_usd_individual + $other_wholesale_usd_individual;
$business_total = $paypal_total_usd_business + $worldpay_total_usd_business + $co_total_usd_business + $wallet_total_usd_business + $other_total_usd_business;
$business_wholesale = $paypal_wholesale_usd_business + $worldpay_wholesale_usd_business + $co_wholesale_usd_business + $wallet_wholesale_usd_business + $other_wholesale_usd_business;
$total_sum = $individual_total + $business_total;
$wholesale_sum = $individual_wholesale + $business_wholesale;

if($total_sum or $wholesale_sum){

	$share_individual = get_persentage($individual_wholesale, $wholesale_sum);
	$share_business = get_persentage($business_wholesale, $wholesale_sum);

	$paypal_share = get_persentage($paypal_wholesale_usd_sum, $wholesale_sum);
	$worldpay_share = get_persentage($worldpay_wholesale_usd_sum, $wholesale_sum);
	$co_share = get_persentage($co_wholesale_usd_sum, $wholesale_sum);
	$wallet_share = get_persentage($wallet_wholesale_usd_sum, $wholesale_sum);
	$other_share = get_persentage($other_wholesale_usd_sum, $wholesale_sum);

	if($paypal_table){
		$paypal_table .= "<tr>
			<td onMouseOver=\"this.style.backgroundColor='#C6FDC7';\" onMouseOut=\"this.style.backgroundColor='';\">
				<table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
				  <tr>
					<td colspan='5' id='irt_headG' align='center'><b>GATEWAY NET REPORT BOX (USD) </b></td>
				  </tr>
				  <tr>
					<td bgcolor='#EBF2E6' align='center'><b>PAYPAL NET</b></td>
					<td id='irt_GS1' align='center'><b>Retail</b></td>
					<td id='irt_GS2' align='center'><b>Wholesale</b></td>
					<td id='irt_GS1' align='center'><b>Share 1</b></td>
					<td id='irt_GS2' align='center'><b>Share</b></td>
				  </tr>
				  <tr>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Individual</td>
					<td id='irt_pr20'>".format_money($paypal_total_usd_individual, 'USD')."</td>
					<td id='irt_pr20'>".format_money($paypal_wholesale_usd_individual, 'USD')."</td>
					<td id='irt_pr20'>$paypal_share_individual %</td>
					<td id='irt_share' rowspan='3' align='center'><b>$paypal_share %</b></td>
				  </tr>
				  <tr>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Business <sup>1</sup> <sup>2</sup> </td>
					<td id='irt_pr20'>".format_money($paypal_total_usd_business, 'USD')."</td>
					<td id='irt_pr20'>".format_money($paypal_wholesale_usd_business, 'USD')."</td>
					<td id='irt_pr20'>$paypal_share_business %</td>
					</tr>
				  <tr>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total</td>
					<td id='irt_pr20'>".format_money($paypal_total_usd_sum, 'USD')."</td>
					<td id='irt_pr20'>".format_money($paypal_wholesale_usd_sum, 'USD')."</td>
					<td id='irt_pr20'>100.00 %</td>
					</tr>
				</table>
			</td>";

		$paypal_table .= '</tr></table><br><br>';
	}

	if($worldpay_table){
		$worldpay_table .= "<tr>
			<td onMouseOver=\"this.style.backgroundColor='#C6FDC7'\" onMouseOut=\"this.style.backgroundColor=''\";><table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_headG' align='center'><b>GATEWAY NET REPORT BOX (USD) </b></td>
			  </tr>
			  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>WORLDPAY NET</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Share 1</b></td>
			<td id='irt_GS2' align='center'><b>Share</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Individual</td>
			<td id='irt_pr20'>".format_money($worldpay_total_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>".format_money($worldpay_wholesale_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>$worldpay_share_individual %</td>
			<td id='irt_share' rowspan='3' align='center'><b>$worldpay_share %</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Business <sup>1</sup> <sup>2</sup> </td>
			<td id='irt_pr20'>".format_money($worldpay_total_usd_business, 'USD')."</td>
			<td id='irt_pr20'>".format_money($worldpay_wholesale_usd_business, 'USD')."</td>
			<td id='irt_pr20'>$worldpay_share_business %</td>
			</tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total</td>
			<td id='irt_pr20'>".format_money($worldpay_total_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>".format_money($worldpay_wholesale_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>100.00 %</td>
			</tr>
			</table></td>
		  </tr>";

		$worldpay_table .= '</table><br><br>';
	}

	if($co_table){
		$co_table .= "<tr>
			<td onMouseOver=\"this.style.backgroundColor='#C6FDC7'\" onMouseOut=\"this.style.backgroundColor=''\";><table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_headG' align='center'><b>GATEWAY NET REPORT BOX (USD) </b></td>
			  </tr>
			  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>2CHECKOUT NET</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Share 1</b></td>
			<td id='irt_GS2' align='center'><b>Share</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Individual</td>
			<td id='irt_pr20'>".format_money($co_total_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>".format_money($co_wholesale_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>$co_share_individual %</td>
			<td id='irt_share' rowspan='3' align='center'><b>$co_share %</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Business <sup>1</sup> <sup>2</sup> </td>
			<td id='irt_pr20'>".format_money($co_total_usd_business, 'USD')."</td>
			<td id='irt_pr20'>".format_money($co_wholesale_usd_business, 'USD')."</td>
			<td id='irt_pr20'>$co_share_business %</td>
				</tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total</td>
			<td id='irt_pr20'>".format_money($co_total_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>".format_money($co_wholesale_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>100.00 %</td>
				</tr>
			</table></td>
		  </tr>";

		$co_table .= '</table><br><br>';
	}

	if($wallet_table){
		$wallet_table .= "<tr>
			<td onMouseOver=\"this.style.backgroundColor='#C6FDC7'\" onMouseOut=\"this.style.backgroundColor=''\";><table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_headG' align='center'><b>GATEWAY NET REPORT BOX (USD) </b></td>
			  </tr>
			  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>WALLET NET</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Share 1</b></td>
			<td id='irt_GS2' align='center'><b>Share</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Individual</td>
			<td id='irt_pr20'>".format_money($wallet_total_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>".format_money($wallet_wholesale_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>$wallet_share_individual %</td>
			<td id='irt_share' rowspan='3' align='center'><b>$wallet_share %</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Business <sup>1</sup> <sup>2</sup> </td>
			<td id='irt_pr20'>".format_money($wallet_total_usd_business, 'USD')."</td>
			<td id='irt_pr20'>".format_money($wallet_wholesale_usd_business, 'USD')."</td>
			<td id='irt_pr20'>$wallet_share_business %</td>
				</tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total</td>
			<td id='irt_pr20'>".format_money($wallet_total_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>".format_money($wallet_wholesale_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>100.00 %</td>
				</tr>
			</table></td>
		  </tr>";

		$wallet_table .= '</table><br><br>';
	}

	if($other_table){
		$other_table .= "<tr>
			<td onMouseOver=\"this.style.backgroundColor='#C6FDC7'\" onMouseOut=\"this.style.backgroundColor=''\";><table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
			  <tr>
			<td colspan='5' id='irt_headG' align='center'><b>GATEWAY NET REPORT BOX (USD) </b></td>
			  </tr>
			  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>OTHER NET</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Share 1</b></td>
			<td id='irt_GS2' align='center'><b>Share</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Individual</td>
			<td id='irt_pr20'>".format_money($other_total_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>".format_money($other_wholesale_usd_individual, 'USD')."</td>
			<td id='irt_pr20'>$other_share_individual %</td>
			<td id='irt_share' rowspan='3' align='center'><b>$other_share %</b></td>
			  </tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Business <sup>1</sup> <sup>2</sup> </td>
			<td id='irt_pr20'>".format_money($other_total_usd_business, 'USD')."</td>
			<td id='irt_pr20'>".format_money($other_wholesale_usd_business, 'USD')."</td>
			<td id='irt_pr20'>$other_share_business %</td>
				</tr>
			  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total</td>
			<td id='irt_pr20'>".format_money($other_total_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>".format_money($other_wholesale_usd_sum, 'USD')."</td>
			<td id='irt_pr20'>100.00 %</td>
				</tr>
			</table></td>
		  </tr>";

		$other_table .= '</table><br><br>';
	}

	$total_reports_table = "<table class='RevTable' width='100%' border='0' cellspacing='1' cellpadding='0'>
	  <tr>
		<td id='BNRB_tab' align='center'><img src='images/ico_billing_net_reportbox.gif' alt='BILLING NET REPORT' align='absmiddle'>&nbsp;&nbsp;<b>BILLING NET REPORT BOX (USD)</b></td>
	  </tr>
	  <tr>
		<td onMouseOver=\"this.style.backgroundColor='#D7F1FF'\" onMouseOut=\"this.style.backgroundColor=''\";><table class='inRevTable' width='100%' border='0' cellspacing='0' cellpadding='2'>
		  <tr>
			<td bgcolor='#EBF2E6' align='center'><b>BILLING NET</b></td>
			<td id='irt_GS1' align='center'><b>Retail</b></td>
			<td id='irt_GS2' align='center'><b>Wholesale</b></td>
			<td id='irt_GS1' align='center'><b>Share 1</b></td>
			<td id='irt_GS2' align='center'><b>Share</b></td>
		  </tr>
		  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Individual</td>
			<td id='irt_pr20'>".format_money($individual_total, 'USD')."</td>
			<td id='irt_pr20'>".format_money($individual_wholesale, 'USD')."</td>
			<td id='irt_pr20'>$share_individual %</td>
			<td id='irt_share' rowspan='3' align='center'><b>100.00 %</b></td>
		  </tr>
		  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Business <sup>1</sup> <sup>2</sup> </td>
			<td id='irt_pr20'>".format_money($business_total, 'USD')."</td>
			<td id='irt_pr20'>".format_money($business_wholesale, 'USD')."</td>
			<td id='irt_pr20'>$share_business %</td>
			</tr>
		  <tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total</td>
			<td id='irt_pr20'>".format_money($total_sum, 'USD')."</td>
			<td id='irt_pr20'>".format_money($wholesale_sum, 'USD')."</td>
			<td id='irt_pr20'>100.00 %</td>
			</tr>
		</table></td>
	  </tr>
	</table>";

	echo $paypal_table.$worldpay_table.$co_table.$wallet_table.$other_table.$total_reports_table;
}elseif($info){
	include($GLOBALS['path'].'no_results.html');
}
?>